﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Solidi
{
    sealed class ConcurrentEnumerable : IEnumerable<object>
    {
        private object _locker;
        private IList<object> _children;

        public ConcurrentEnumerable(IList<object> children, object locker)
        {
            _children = children;
            _locker = locker;
        }

        public IEnumerator<object> GetEnumerator()
        {
            lock (_locker)
            {
                return _children.ToList().GetEnumerator();
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
